import {defineConfig, loadEnv} from "vite";
import postcssConfig from './postcss.config'
import uni from "@dcloudio/vite-plugin-uni";
import uvtw from '@uni-helper/vite-plugin-uni-tailwind'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'

// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
  const env = loadEnv(mode, process.cwd(), '');
  return {
    css: {
      postcss: postcssConfig,
      preprocessorOptions: {
        scss: {
          api: 'modern-compiler', // 防止运行时弹出警告 Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.
          silenceDeprecations: ['legacy-js-api'] // 防止运行时弹出警告 Deprecation Warning: The legacy JS API is deprecated and will be removed in Dart Sass 2.0.0.
        }
      },
    },
    plugins: [
      uni(),
      uvtw(),
      AutoImport({
        imports: ['vue', 'pinia','uni-app','vue-router'],
      }),
      Components({
        dirs: ['src/components'], // 配置需要默认导入的自定义组件文件夹，该文件夹下的所有组件都会自动 import
      }),
    ],
    server: {
      proxy: {
        "/api" : {
          target: env.VITE_APP__API_URL + '/api',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      },
      port: 5173,
      open: false,
    }
  }
});
